//
//  DetailCellViewController.m
//  老司机发车了
//
//  Created by 程成 on 16/8/8.
//  Copyright © 2016年 斌. All rights reserved.
//

#import "DetailCellViewController.h"
#import "MBManager.h"

@interface DetailCellViewController ()<UIWebViewDelegate>
/*webView*/
@property (strong, nonatomic )UIWebView *webView;
/*url*/
@property (copy, nonatomic )NSString *urlStr;
/*string2*/
@property (copy, nonatomic )NSString *string2;
@end

@implementation DetailCellViewController
-(void)setWebView1{
    NSString *string1 = [_skipid substringWithRange:NSMakeRange(4, 4)];
    NSArray *array = [_skipid componentsSeparatedByString:@"|"];
    self.string2 = array.lastObject;

    NSString *string = [NSString stringWithFormat:@"%@/%@",string1, _string2];
    NSString *url = [NSString stringWithFormat:PhotoCellUrl,string];

    [NetWorkRequestManager requestWithType:GET urlString:url parDic:@{} finish:^(NSData *data) {
        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
        self.urlStr = dictionary[@"url"];
    } finishError:^(NSError *error) {
        NSLog(@"解析错误");
    }];

    self.webView = [[UIWebView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:_webView];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_urlStr]];
    [_webView loadRequest:request];
    self.webView.delegate = self;
    [MBManager showLoadingInView:self.view];

}
- (void)setWebView2{
    self.webView = [[UIWebView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:_webView];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_urlString]];
    [_webView loadRequest:request];
    self.webView.delegate = self;

    //加载动画
    [MBManager showLoadingInView:self.view];

    


}
//监听 webView 加载完成
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    //去除 HUD
    [MBManager hideAlert];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    if (_index == 1|| _index == 3) {
        [self setWebView1];
    }else if(_index == 2){
        [self setWebView2];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
